#ifndef HFT_SIMULATED_EXECUTION_ENGINE_H
#define HFT_SIMULATED_EXECUTION_ENGINE_H

#include "execution/execution_engine.h"
#include <string>
#include <unordered_map>
#include <functional>
#include <chrono>
#include <thread>
#include <random>

namespace hft {

class SimulatedExecutionEngine : public ExecutionEngine {
public:
    SimulatedExecutionEngine();
    
    // ExecutionEngine接口实现
    bool sendOrder(const Order& order) override;
    bool modifyOrder(const Order& order) override;
    bool cancelOrder(const Order& order) override;
    
    void setOrderCallback(std::function<void(const Order&)> callback) override;
    void setTradeCallback(std::function<void(const Trade&)> callback) override;
    
    bool connect() override;
    void disconnect() override;
    bool isConnected() const override;
    
    int64_t getExchangeTime() const override;
    
    // 模拟引擎特有方法
    void updateMarketPrice(const std::string& symbol, double price);
    void setSimulatedLatency(int latency_ms);
    void setFillProbability(double probability);

private:
    bool is_connected_;
    int simulated_latency_ms_;
    double fill_probability_;
    int next_trade_id_;
    std::unordered_map<std::string, double> market_prices_;
    std::function<void(const Order&)> order_callback_;
    std::function<void(const Trade&)> trade_callback_;
    
    void processOrderMatch(Order& order);
    void generateSimulatedTrade(Order& order, int volume, double price);
};

} // namespace hft

#endif // HFT_SIMULATED_EXECUTION_ENGINE_H